﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CNotebook;
using CNotebook.Inventory;
using DevExpress.XtraBars.Ribbon;
namespace NotebookS2
{
    public partial class StockStatus : RibbonForm
    {
        public StockStatus()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }
        void BindWarehouse()
        {
            WarehouseManager oManager = new WarehouseManager();
            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            DataTable oTable = new DataTable();

            oTable = oManager.GetWarehouse();


            cboWarehouse.Visible = false;
            cboWarehouse.Properties.DataSource = oTable;
            cboWarehouse.Properties.DisplayMember = "Dscription";
            cboWarehouse.Properties.ValueMember = "Code";

            DevExpress.XtraEditors.Controls.LookUpColumnInfo col;

            col = new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Code", "Code", 100);

            col.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;

            
            cboWarehouse.Properties.Columns.Add(col);

            col = new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Dscription", "Dscription", 100);

            cboWarehouse.Properties.Columns.Add(col);

            cboWarehouse.Visible = true;


            oManager.Close();


            
        }

        void BindStocks(string _WhsCode)
        {
            StockManager oManager = new StockManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            DataTable _table = oManager.GetStocksByWarehouse(_WhsCode);

            gridControl1.DataSource = _table;
            gridControl1.Refresh();
            gridView1.ExpandAllGroups();
            oManager.Close();
        }

        public void PrintPreview()
        {
            if (!gridControl1.IsPrintingAvailable)
            {
                MessageBox.Show("The 'DevExpress.XtraPrinting' Library is not found", "Error");
                return;
            }
            // Opens the Preview window. 
            gridControl1.ShowPrintPreview();
        }
        private void StockCardInfo_Load(object sender, EventArgs e)
        {
            BindWarehouse();
        }

        private void cboWarehouse_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void cboWarehouse_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                BindStocks(cboWarehouse.EditValue.ToString());
            }
            catch
            {
                gridControl1.DataSource = null;
                gridControl1.Refresh();
            }
        }

        private void cboWarehouse_DragOver(object sender, DragEventArgs e)
        {

        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {

            try
            {
                BindStocks(cboWarehouse.EditValue.ToString());
            }
            catch
            {
                gridControl1.DataSource = null;
                gridControl1.Refresh();
            }
        }
    }
}
